#define _CRT_SECURE_NO_WARNINGS 1		
#include"Slist.h"
void insertSlist(Slist**pphead, Slisttype1 data3, Slisttype2 data4)
{
	Slist* newnode = (Slist*)malloc(sizeof(Slist));
	newnode->next = NULL;
	newnode->data1 = data3;
	newnode->data2 = data4;
	if (*pphead == NULL)
	{
		*pphead = newnode;
	}
	else
	{
		Slist* tail = *pphead;
		while (tail->next != NULL)
		{
			tail = tail->next;
		}
		tail->next = newnode;
	}
}
void Slistadd(Slist** pphead1, Slist** pphead2)
{
	assert(*pphead1 != NULL && *pphead2);
	Slist* head1 = *pphead1;
	Slist* head2 = *pphead2;
	Slist* head01 = *pphead1, * head02 = *pphead2;
	Slist* tem = NULL;
	while (head1 && head2)
	{
		Slisttype2 a = head1->data2, b = head2->data2;
		switch (numcmp(a, b))
		{
		case 1:
			if (head1 == head01)
			{
				while (head2->next->data2 < a)
				{
					head2 = head2->next;
				}
				Slist* tmp = head2->next;
				head2->next = head01;
				head2 = tmp;
			}
			else
			{
				head2 = head2->next;
				break;
			}
		case 0:
			head1->data1 += head2->data1;
			if (head1->next != NULL)
			{
				head1 = head1->next, head2 = head2->next;
			}
			else
			{
				tem = head1;
				head1 = head1->next, head2 = head2->next;
			}
			break;
		case -1:
			head1 = head1->next;
			break;
		}
	}
	if (head2)
	{
		tem->next = head2;
	}
}
void Slistprint(Slist* phead)
{
	Slist* head = phead;
	while (head != NULL)
	{
		printf("%d,%d ", head->data1, head->data2);
		head=head->next;
	}
}
int numcmp(num1, num2)
{
	if (num1 > num2)
	{
		return 1;
	}
	else if (num1 == num2)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}